import { defineConfig } from 'vite'
import * as path from 'path'
import glslify from 'rollup-plugin-glslify';
import headerFooterPlugin from "./vite-plugin-header-footer";
import pxToViewport from "postcss-px-to-viewport"
import autoprefixer from "autoprefixer"
export default defineConfig({
  root: 'src',
  base: './',
  build: {
    outDir: '../dist',
    rollupOptions: {
      input: {
        index:path.resolve(__dirname, 'src/index.html'),
        about:path.resolve(__dirname, 'src/about.html'),
        application:path.resolve(__dirname, 'src/application.html'),
        case:path.resolve(__dirname, 'src/case.html'),
        news:path.resolve(__dirname, 'src/news.html'),
        media:path.resolve(__dirname, 'src/media.html'),
        newDetail:path.resolve(__dirname, 'src/newDetail.html'),
        contact:path.resolve(__dirname, 'src/contact.html'),
        proItem:path.resolve(__dirname, 'src/proItem.html'),
        proDetail:path.resolve(__dirname, 'src/proDetail.html'),
        recruit:path.resolve(__dirname, 'src/recruit.html'),
        tech:path.resolve(__dirname, 'src/tech.html'),
        search:path.resolve(__dirname, 'src/search.html'),
        law:path.resolve(__dirname, 'src/law.html'),
        policy:path.resolve(__dirname, 'src/policy.html'),
      },
      output:{
        entryFileNames: `assets/[name].js`,
        chunkFileNames: `assets/[name].js`,
        assetFileNames: `assets/[name].[ext]`,
      }
    },
  },
  server: {
    host: true, // to test on other devices with IP address
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  css:{
    postcss:{
      plugins:[
        autoprefixer({
          overrideBrowserslist: [
            "Android 4.1",
            "iOS 7.1",
            "Chrome > 31",
            "ff > 31",
            "ie >= 8"
          ],
        }),
        pxToViewport({//https://www.npmjs.com/package/px-2-vw-units
          unitToConvert: 'px',//要转换的（字符串）单位，默认情况下为 px
          viewportWidth:1920,//视口的宽度
          unitPrecision:5,//允许 vw 单位增长到的十进制数
          propList:['*'],
          viewportUnit:'vw',//预期单位
          minPixelValue:10,//设置要替换的最小像素值
          mediaQuery:false,//允许在媒体查询中转换 px
        })
      ]
    }
  },
  plugins: [
      glslify(),
      headerFooterPlugin()
  ],
})
